import utils.TreeNode;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/9 15:50
 * @description:
 */
public class LCR174 {
    public int m = 0;
    public int findTargetNode(TreeNode root, int cnt) {
        if (root == null) {
            return -1;
        }
        int right = findTargetNode(root.right, cnt);
        if (right != -1) {
            return right;
        }

        m++;
        if (m == cnt) {
            return root.val;
        }
        int left = findTargetNode(root.left, cnt);
        if (left != -1) {
            return left;
        }
        return -1;
    }
}
